import Vue from 'vue'
import VueRouter from 'vue-router'

// layout
import Main from '@/views/main/Main.vue'
// pages
const page404 = () => import('@/views/404.vue')
const Home = () => import('@/views/main/Home.vue')
const PersonCenter = () => import('@/views/main/PersonCenter.vue')
const GuaranteeSlip = () => import('@/views/main/GuaranteeSlip.vue')
const SettlementOfClaim = () => import('@/views/main/SettlementOfClaim.vue')

/**
 * 重写路由的push方法
 */
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}


Vue.use(VueRouter)
// 注意
// meta: {
//   isOpen: true // 默认所有页面都是要权限的,配置isOpen:true 设置无需权限访问
// }
const routes = [
  {
    path: '/',
    name: 'main',
    redirect: '/home',
    component: Main,
    children: [
      {
        path: 'home',
        name: 'home',
        meta: {
          title: '首页',
          isOpen: true
        },
        component: Home
      },
      {
        path: 'personCenter',
        name: 'personCenter',
        meta: {
          title: '个人中心',
          isOpen: true
        },
        component: PersonCenter
      },
      {
        path: 'guaranteeSlip',
        name: 'guaranteeSlip',
        meta: {
          title: '保单'
        },
        component: GuaranteeSlip
      },
      {
        path: 'settlementOfClaim',
        name: 'settlementOfClaim',
        meta: {
          title: '理赔'
        },
        component: SettlementOfClaim
      }
    ]
  },
  {
    path: '/policyQueryCriteria',
    name: 'policyQueryCriteria',
    meta: {
      title: '保单查询条件',
      isOpen: true
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/PolicyQueryCriteria.vue')
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
      isOpen: true
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/Login.vue')
  },
  {
    path: '/policyDetails',
    name: 'policyDetails',
    meta: {
      title: '保单详情',
      isOpen: true
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/policyDetails.vue')
  },
  {
    path: '/contactUs',
    name: 'contactUs',
    meta: {
      title: '联系我们',
      isOpen: true
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/ContactUs.vue')
  },
  {
    path: '/account',
    name: 'account',
    meta: {
      title: '账户维护'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/Account.vue')
  },
  {
    path: '/editAccount',
    name: 'editAccount',
    meta: {
      title: '账户修改'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/EditAccount.vue')
  },
  {
    path: '/changePassword',
    name: 'changePassword',
    meta: {
      title: '修改密码'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/ChangePassword.vue')
  },
  {
    path: '/forgotPassword',
    name: 'forgotPassword',
    meta: {
      title: '忘记密码',
      isOpen: true
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/forgotPassword.vue')
  },
  
  {
    path: '/changeOrder',
    name: 'changeOrder',
    meta: {
      title: '改单'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/ChangeOrder.vue')
  },
  {
    path: '/reportCase',
    name: 'reportCase',
    meta: {
      title: '报案'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/ReportCase.vue')
  },
  
  {
    path: '/reportCaseNext',
    name: 'reportCaseNext',
    meta: {
      title: '报案'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/ReportCaseNext.vue')
  },
  {
    path: '/bankAccount',
    name: 'bankAccount',
    meta: {
      title: '银行账户'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/BankAccount.vue')
  },
  {
    path: '/addBankAccount',
    name: 'addBankAccount',
    meta: {
      title: '新增银行账户'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/AddBankAccount.vue')
  },
  {
    path: '/wallet',
    name: 'wallet',
    meta: {
      title: '我的钱包'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/Wallet.vue')
  },
  {
    path: '/walletDetall',
    name: 'walletDetall',
    meta: {
      title: '我的钱包'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/WalletDetall.vue')
  },
  {
    path: '/track',
    name: 'track',
    meta: {
      title: '跟踪'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/Track.vue')
  },
  {
    path: '/applicant',
    name: 'applicant',
    meta: {
      title: '常用投保人'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/Applicant.vue')
  },
  {
    path: '/addApplicant',
    name: 'addApplicant',
    meta: {
      title: '新增常用投保人'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/AddApplicant.vue')
  },
  {
    path: '/invoiceMsg',
    name: 'invoiceMsg',
    meta: {
      title: '发票信息'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/invoiceMsg.vue')
  },
  {
    path: '/addInvoice',
    name: 'addInvoice',
    meta: {
      title: '新增发票'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/addInvoice.vue')
  },
  {
    path: '/message',
    name: 'message',
    meta: {
      title: '消息'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/Message.vue')
  },
  {
    path: '/temp1',
    name: 'temp1',
    meta: {
      title: '国内货运险'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/InsuranceType/temp1/index.vue')
  },
  {
    path: '/tempInput',
    name: 'tempInput',
    meta: {
      title: '投保'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/InsuranceType/temp1/temp-index.vue')
  },
  {
    path: '/recharge',
    name: 'recharge',
    meta: {
      title: '充值'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/recharge.vue')
  },
  {
    path: '/revAndExp',
    name: 'revAndExp',
    meta: {
      title: '收支明细'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/RevAndExp.vue')
  },
  {
    path: '/retrievePassword',
    name: 'retrievePassword',
    meta: {
      title: '找回密码'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/RetrievePassword.vue')
  },
  {
    path: '/accountChange',
    name: 'accountChange',
    meta: {
      title: '账户变更'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/AccountChange.vue')
  },
  {
    path: '/rechargeIndex',
    name: 'rechargeIndex',
    meta: {
      title: '充值'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/RechargeIndex.vue')
  },
  {
    path: '/customerNotification',
    name: 'customerNotification',
    meta: {
      title: '客户告知书'
    },
    component: () => import(/* webpackChunkName: "login" */ '@/views/main/CustomerNotification.vue')
  },
  // {
  //   path: '/regAgreement',
  //   name: 'regAgreement',
  //   meta: {
  //     title: '同意协议',
  //     isOpen: true
  //   },
  //   component: () => import(/* webpackChunkName: "login" */ '@/views/main/RegAgreement.vue')
  // },
  {
    path: '*',
    name: 'page404',
    meta: {
      title: '页面未找到'
    },
    component: page404
  }
]

const router = new VueRouter({
  routes
})

export default router
